<template>
  <aside class="site-sidebar" :class="'site-sidebar--' + sidebarLayoutSkin">
    <div class="site-sidebar__inner">
      <el-menu
        v-if="show"
        :default-active="menuActiveName || 'home'"
        :collapse="sidebarFold"
        :collapseTransition="false"
        @select="handleSelect"
        class="site-sidebar__menu">
        <el-menu-item :class='{"site-home site-homes":sidebarFold,"site-home":!sidebarFold}' index="home" @click="$router.push({ name: 'home' })">
          <icon-svg name="shouyede" class="site-sidebar__menu-icon"></icon-svg>
          <span slot="title">首页</span>
        </el-menu-item>
        <sub-menu
        class="sub-meunlist"
          v-for="menu in menuList"
          :key="menu.menuId"
          :menu="menu"
          @click="clickMenuList()"
          :dynamicMenuRoutes="dynamicMenuRoutes">
        </sub-menu>
      </el-menu>
    </div>
  </aside>
</template>

<script>
  import SubMenu from './main-sidebar-sub-menu'
  import { isURL } from '@/utils/validate'
  import { eventBus } from '../../eventBus'
  export default {
    data () {
      return {
        dynamicMenuRoutes: [],
        indexClass:'',
        show: true,
        // certificateinfolist: true,
      }
    },
    components: {
      SubMenu
    },
    mounted () {
    },
    computed: {
      sidebarLayoutSkin: {
        get () { return this.$store.state.common.sidebarLayoutSkin }
      },
      sidebarFold: {
        get () { return this.$store.state.common.sidebarFold }
      },
      menuList: {
        get () { return this.$store.state.common.menuList },
        set (val) { this.$store.commit('common/updateMenuList', val) }
      },
      menuActiveName: {
        get () { return this.$store.state.common.menuActiveName },
        set (val) { this.$store.commit('common/updateMenuActiveName', val) }
      },
      mainTabs: {
        get () { return this.$store.state.common.mainTabs },
        set (val) { this.$store.commit('common/updateMainTabs', val) }
      },
      mainTabsActiveName: {
        get () { return this.$store.state.common.mainTabsActiveName },
        set (val) { this.$store.commit('common/updateMainTabsActiveName', val) }
      }
    },
    watch: {
      $route: 'routeHandle'
    },
    created () {
      this.menuList = JSON.parse(sessionStorage.getItem('menuList') || '[]')
      this.dynamicMenuRoutes = JSON.parse(sessionStorage.getItem('dynamicMenuRoutes') || '[]')
      this.routeHandle(this.$route)

    },
    methods: {
      clickMenuList(){
      },
      clicksubItem(msg){
      if(msg == 83) {
        console.log(msg);
        this.$router.push({ name: 'certificate-certificateinfolist' })
      }
      },
      //  点击操作菜单栏
      handleSelect(key,index){


      var arr = JSON.parse(sessionStorage.getItem('menuList'));
      var arrList = []

/*       arr.forEach(i=>{
        arrList.push(i.list)
      }) */

      console.log(arrList);


      console.log(key);
      if(key == 174) {
        eventBus.$emit("pmlist",true)
      }
      if(key == 167) {
        eventBus.$emit("pmstatistics",true)
      }
      if(key == 83) {
        eventBus.$emit("certificateinfolist",true)
      }
      if(key == 136) {
        eventBus.$emit("warn",true)
      }
      if(key == 86) {
        eventBus.$emit("certificateinforenewal",true)
      }
      if(key == 149) {
        eventBus.$emit("qualification",true)
      }
      if(key == 150) {
        eventBus.$emit("iso",true)
      }
      if(key == 151) {
        eventBus.$emit("honor",true)
      }
      if(key == 152) {
        eventBus.$emit("rest",true)
      }
      if(key == 154) {
        eventBus.$emit("warning",true)
      }
      if(key == 137) {
        eventBus.$emit("personnel",true)
      }
      if(key == 87) {
        eventBus.$emit("deptInfo",true)
      }
      if(key == 88) {
        eventBus.$emit("employee",true)
      }
      if(key == 156) {
        eventBus.$emit("particularsincome",true)
      }
      if(key == 84) {
        eventBus.$emit("certificateinfoadd",true)
      }
      // if(key == 83) {
      //   eventBus.$emit("certificateinfolist",true)
      // }
       this.$emit('indexClass',key)
      },
      // 路由操作
      routeHandle (route) {
        if (route.meta.isTab) {
          // tab选中, 不存在先添加
          var tab = this.mainTabs.filter(item => item.name === route.name)[0]
          if (!tab) {
            if (route.meta.isDynamic) {
              route = this.dynamicMenuRoutes.filter(item => item.name === route.name)[0]
              if (!route) {
                return console.error('未能找到可用标签页!')
              }
            }
            tab = {
              menuId: route.meta.menuId || route.name,
              name: route.name,
              title: route.meta.title,
              type: isURL(route.meta.iframeUrl) ? 'iframe' : 'module',
              iframeUrl: route.meta.iframeUrl || ''
            }
            this.mainTabs = this.mainTabs.concat(tab)
          }
          this.menuActiveName = tab.menuId + ''
          this.mainTabsActiveName = tab.name
        }
      }
    }
  }
</script>
<style lang="scss" scoped>
/deep/.site-homes.is-active {
  background: #2B3357 !important;
  border-radius: 6px !important;
  opacity: 1;
}

/deep/.site-sidebar__inner{
  .site-sidebar__menu{
    .site-home{
      height: 40px !important;
      line-height: 40px !important;
      margin-bottom: 10px !important;
      .el-tooltip{
        padding-left: 10px !important;
      }
    }
  }
}
/deep/.site-sidebar__inner{
  .site-sidebar__menu{
   .sub-meunlist{
     .el-menu--inline{
       .el-menu-item{
         padding-left: 10px !important;
         margin-left: 10px !important;
         margin-right: 10px !important;
       }
     }
   }
  }
}
/deep/.site-sidebar__inner{
.site-sidebar__menu.el-menu{
  margin-bottom: 40px !important;
}
}
</style>
